<!-- 供配电 》 数据监测 -->

<template>
  <CommonBody class="ElecData" hasTree :tree="elec_tree" :field="elec_TREE_FIELD" initRoot diy @change="setOne">
    <EasyCard>
      <DetailForm />
      <DetailTable />
    </EasyCard>

    <EasyCard class="marginBottom">
      <template #title>
        <RecordTitle />
      </template>

      <div v-if="one.tab === 'realtime'">
        <RealTimeSearch />
        <RealtimeTable />
      </div>

      <div v-else-if="one.tab === 'history'">
        <HistorySearch />
        <HistoryTable />
      </div>
    </EasyCard>

    <HistoryModal />
  </CommonBody>
</template>

<script>
// ============================== 导入依赖 ============================== //

import CORE from '@/CORE'
import store from './store'

// ============================== 导出组件 ============================== //

export default {
  /**
   * 名称定义 (实际使用名称)
   */
  name: 'ElecData',

  /**
   * 混入列表 (配置选项合并)
   */
  mixins: [CORE.mixStore(store)],

  /**
   * 组件导入 (Abc.vue + Abc/index.vue)
   */
  ...CORE.components(require.context('./', true, /vue$/)),

  /**
   * 监听属性 (深度 deep 首次 immediate)
   */
  watch: {
    /**
     * 监听结构树就绪
     */
    elec_readyTree(ready) {
      if (ready) {
        const { param, one, elec_treeMap, elec_tree, setOne } = this
        const chosen = one.id ? elec_treeMap[one.id] : elec_tree[0]
        param.treeId = chosen.id
        setOne(chosen)
      }
    },

    /**
     * 监听单项 ID
     */
    'one.id'(id) {
      // 除监测点 ID 外重置所有参数后再查询
      this.realtime_INIT_PARAM.monitorPointSiteId = id
      this.realtime_setParam()
      this.realtime_startList()

      this.history_INIT_PARAM.monitorPointSiteId = id
      this.history_setParam()
      this.history_startList()
    },
  },
}
</script>
